package servlet;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.User;
import dao.impl.UserHandleImpl;

/**
 * Servlet implementation class HandleImgSerlet
 */
public class HandleImgSerlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	UserHandleImpl uhi = new UserHandleImpl();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HandleImgSerlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String username = request.getParameter("name");
		User user = uhi.loadUser(username);
		if (user != null) {
			byte[] bytes = user.getAvatar();
			OutputStream out = response.getOutputStream();
			response.setContentType("image/jpeg;charset=utf-8");
			out.write(bytes);
			out.close();
		}
	}

}
